package cn.safeness.web.conf;

import cn.safeness.entity.system.account.ManagerEntity;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;

/**
 * @Program management
 * @Description spring security user
 * @Anthor vinson
 * @Create 2018-02-27 15:04
 */
public class SecurityUser implements UserDetails{

    private Integer id;
    private String name;
    private String password;
    private String tel;
    private String email;
    private Collection<GrantedAuthority> authorities;// 用户证书是否有效


    public SecurityUser(ManagerEntity user){
        this.id = user.getId();
        this.name = user.getName();
        this.password = user.getPassword();
        this.tel = user.getTel();
        this.email = user.getEmail();
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    public void setAuthorities(Collection<GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.name;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    public Integer getId() {
        return id;
    }

    public String getTel() {
        return tel;
    }

    public String getEmail() {
        return email;
    }
}
